package com.dc.datacollect.config;

import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Slf4j
@Component
public class CustomIdGenerator implements IdentifierGenerator {

    @Override
    public Long nextId(Object entity) {
        //可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
        int max = 999;
        String characters = String.valueOf( (int)(Math.random()  * (max+1)));
        String tail = Covering(characters,4);
        return Long.valueOf(System.currentTimeMillis() + tail);
    }

    public String Covering(Object base,int desireLength) {
        StringBuilder result = new StringBuilder(base.toString());
        int  complementNumber = desireLength - result.length();
        for (int i = 0; i < complementNumber; i++) {
            result.append("0");
        }
        return result.toString();
    }

}